package cn.cloud.butler.webapi.controller;

import cn.cloud.butler.webapi.domain.HealhSecurityEntity;
import cn.cloud.butler.webapi.domain.ResponseEntity;
import cn.cloud.butler.webapi.logger.WaLogger;
import cn.cloud.butler.webapi.service.MachineHealthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * author: daichaoren
 * time: 2019-01-07
 * description: 机床健康类接口
 */
@RestController
@EnableAutoConfiguration
@RequestMapping("/HncWeb")
public class MachineHealthController {

    @Autowired
    MachineHealthService machineHealthService;
    //接口64
    //单台机床健康状态趋势图
    //http://10.10.56.52:8080/HncWeb/healTendency.action?macsn=20CF1B9BDFF3733<br>
    @RequestMapping(method = RequestMethod.GET,value = "/healTendency.action")
    public ResponseEntity healTendency(String macsn){
        ResponseEntity response = new ResponseEntity();
        try{
            List<HealhSecurityEntity> proList =  machineHealthService.healTendency(macsn);
            response.setMsgDesc("查询成功");
            response.setMsgCode(0);
            response.setData(proList);
        }catch (Exception e){
            response.setMsgCode(1);
            response.setMsgDesc(e.toString());
            WaLogger.logger.warn(e.toString());
        }
        return  response;
    }

    //接口53
    //查询最新的一条健康保障数据
    //http://10.10.56.52:8080/HncWeb/LastHealthSecurity.action?macsn=002<br>
    @RequestMapping(method=RequestMethod.GET,value = "/LastHealthSecurity.action")
    public ResponseEntity LastHealthSecurity(String macsn){
        ResponseEntity result = new ResponseEntity();
        try{
            List<HealhSecurityEntity> data = machineHealthService.LastHealthSecurity(macsn);
            result.setMsgCode(0);
            result.setMsgDesc("查询成功");
            result.setData(data);
        }catch (Exception e){
            result.setMsgCode(1);
            result.setMsgDesc(e.toString());
            WaLogger.logger.warn(e.toString());

        }
        return result;
    }

    /**
     * 查询多台机床所有的健康状态值，通过传递不同的type确定y轴不同
     * http://10.10.56.73:8080/HncWeb/MoreMacHealthOneTerm.action?macsns=002,003,004&type=mainAxis
     * @param type 轴类型
     * @param macsns 机床SN列表
     * @return ResponseEntity
     */
    @RequestMapping(method=RequestMethod.GET,value = "/MoreMacHealthOneTerm.action")
    public ResponseEntity MoreMacHealthOneTerm(String type,String macsns){
        ResponseEntity result = new ResponseEntity();
        try{
            List<HashMap<String,Object>> data = machineHealthService.moreMacHealthByType(type,macsns);
            result.setMsgCode(0);
            result.setMsgDesc("查询成功");
            result.setData(data);
        }catch (Exception e){
            result.setMsgCode(1);
            result.setMsgDesc(e.toString());
            WaLogger.logger.warn(e.toString());

        }
        return result;
    }
}
